using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Networking;

[RequireComponent(typeof(NetworkIdentity))]
public class ItemData : NetworkBehaviour
{
	public Sprite ImageSprite;

	public string ItemName;

	public string Description;

	public int Price;

	public bool Stack = true;

	public bool UniqueItem;

	public bool HideOnUse = true;

	public FPSItemEquipment ItemFPS;

	public ItemEquipment ItemEquip;

	[SyncVar]
	public int Quantity = 1;

	[SyncVar]
	[HideInInspector]
	public int NumTag = -1;

	public AudioClip SoundPickup;

	public string ItemID;

	[HideInInspector]
	public int ItemIndex;

	public bool SavePreviousUse = true;

	public int NetworkQuantity
	{
		get
		{
			return Quantity;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref Quantity, 1u);
		}
	}

	public int NetworkNumTag
	{
		get
		{
			return NumTag;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref NumTag, 2u);
		}
	}

	public virtual void Pickup(GameObject character)
	{
		character.SendMessage("PickupItemCallback", this);
		RemoveItem();
	}

	public void SetupDrop(int numtag, int num)
	{
		NetworkNumTag = numtag;
		NetworkQuantity = num;
	}

	public void RemoveItem()
	{
		UnityEngine.Object.Destroy(base.gameObject);
	}

	public void GetInfo()
	{
		string info = "Press F to Pickup\n" + ItemName + " x " + Quantity;
		UnitZ.Hud.ShowInfo(info, base.transform.position);
	}

	private void UNetVersion()
	{
	}

	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		if (forceAll)
		{
			writer.WritePackedUInt32((uint)Quantity);
			writer.WritePackedUInt32((uint)NumTag);
			return true;
		}
		bool flag = false;
		if ((base.syncVarDirtyBits & 1) != 0)
		{
			if (!flag)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag = true;
			}
			writer.WritePackedUInt32((uint)Quantity);
		}
		if ((base.syncVarDirtyBits & 2) != 0)
		{
			if (!flag)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag = true;
			}
			writer.WritePackedUInt32((uint)NumTag);
		}
		if (!flag)
		{
			writer.WritePackedUInt32(base.syncVarDirtyBits);
		}
		return flag;
	}

	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		if (initialState)
		{
			Quantity = (int)reader.ReadPackedUInt32();
			NumTag = (int)reader.ReadPackedUInt32();
			return;
		}
		int num = (int)reader.ReadPackedUInt32();
		if ((num & 1) != 0)
		{
			Quantity = (int)reader.ReadPackedUInt32();
		}
		if ((num & 2) != 0)
		{
			NumTag = (int)reader.ReadPackedUInt32();
		}
	}
}
